package com.cssnj.portal.config;

import io.predictech.framework.utility.LogUtil;
import io.predictech.framework.utility.PredictechUtil;
import org.springframework.beans.factory.annotation.Qualifier;
import org.springframework.boot.autoconfigure.jdbc.DataSourceProperties;
import org.springframework.boot.context.properties.ConfigurationProperties;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.jdbc.core.JdbcTemplate;

import javax.sql.DataSource;


@Configuration
public class FourthDataSourceConfig {

    @Bean
    @ConfigurationProperties("spring.fourth.datasource")
    public DataSourceProperties fourthDataSourceProperties() {
        return new DataSourceProperties();
    }

    @Bean(destroyMethod = "")
    @ConfigurationProperties("spring.fourth.datasource")
    public DataSource fourthDataSource() {
        LogUtil.systemLogger().info("Registering Fourth Data Source");
        DataSourceProperties dataSourceProperties = fourthDataSourceProperties();
        return PredictechUtil.getDataSource(dataSourceProperties);
    }

    @Bean(name = "fourthJdbcTemplate")
    public JdbcTemplate fourthJdbcTemplate(@Qualifier("fourthDataSource") DataSource dataSource) {
        return new JdbcTemplate(dataSource);
    }
}
